/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-08
 * Time: 18:31
 */
class MyBlockingQueue {
    //先写一个循环队列
    private String[] items = new String[1000];
    volatile int head = 0;
    private volatile int tail = 0;
    private volatile int size = 0;
    private Object loket = new Object();

    void put(String string) throws InterruptedException {
        synchronized (loket) {
            while (size >= items.length) {
                loket.wait();
            }
        }
        items[tail] = string;
        tail++;
        if (tail >= items.length) {
            tail = 0;
        }
        size++;
        loket.notify();
    }

    String take() throws InterruptedException {
        synchronized (loket) {
            while (size == items.length) {
                loket.wait();
            }
        }
        String elem = items[head];
        head++;
        if (head >= items.length) {
            head = 0;
        }
        size--;
        loket.notify();
        return elem;
    }
}

public class test_3 {
}
